<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% pageContext.setAttribute("basePath", request.getContextPath()); %>
<script type="text/javascript" src="${basePath}/static/js/jquery-3.6.0.min.js"></script>
<link href="${basePath}/static/bootstrap-3.4.1-dist/css/bootstrap.css" rel="stylesheet">
<script src="${basePath}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>公告信息管理</title>
</head>
<body>
<div class="container2">
    <div style="width:12%;text-align:left;margin-left:30px;margin-right:30px;">
        <br/><br/><br/>
        <ul class="nav nav-pills nav-stacked">
            <li><a href="${basePath}/user/list">学生信息管理</a></li>
            <br>
            <li><a href="${basePath}/teacher/list">教师信息管理</a></li>
            <br>
            <li><a href="${basePath}/content/list">课程信息管理</a></li>
            <br>
            <li class="active"><a href="${basePath}/score/list">学生成绩管理</a></li>
        </ul>
    </div>
    <div style="width:88%;text-align: left;margin-left:20px;margin-right:30px;">
        <div>
            <nav class="navbar navbar-default" role="navigation">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <a class="navbar-brand" href="#">学生信息管理系统</a>
                    </div>
                    <ul class="nav navbar-nav navbar-right">
                        <li id="logout" style="margin-top:15px;margin-right: 30px;"><span
                                class="glyphicon glyphicon-user"></span>退出登录
                        </li>
                    </ul>
                </div>
            </nav>
        </div>
        <h4>新增</h4>
        <br/>
        <div>
            <div style="display: flex">
                <div style="width: 80px;margin-top:8px;">
                    <span>学生：</span>
                </div>
                <div>
                    <select class="form-control" style="width:200px;" id="user">
                        <c:forEach items="${userList}" var="item">
                            <option value="${item.uid}">${item.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <br/>
            <div style="display: flex">
                <div style="width: 80px;margin-top:8px;">
                    <span>课程：</span>
                </div>
                <div>
                    <select class="form-control" style="width:200px;" id="content">
                        <c:forEach items="${contentList}" var="item">
                            <option value="${item.uid}">${item.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <br/>
            <div style="display: flex">
                <div style="width: 80px;margin-top:8px;">
                    <span>成绩：</span>
                </div>
                <div>
                    <input type="text" class="form-control" id="score" placeholder="" style="width:400px">
                </div>
            </div>
            <br/>
            <div style="text-align: left;">
                <button type="button" class="btn btn-danger btn-sm" onclick="addUser(this)" style="width: 100px;">保存
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function addUser(obj) {
        let param = {
            user: $("#user").val(),
            score: $('#score').val(),
            content: $("#content").val(),
        }
        let objParam = JSON.stringify(param);
        $.ajax({
            url: '${basePath}/score/add',//地址
            dataType: 'json',//数据类型
            type: 'POST',//类型
            timeout: 5000,//超时
            data: objParam,
            contentType: "application/json",
            //请求成功
            success: function (data) {
                <%--if (data.returnCode === '401') {--%>
                <%--    window.location.href = "${basePath}/";--%>
                <%--}--%>
                <%--if (data.returnCode !== '200') {--%>
                <%--    alert(data.message);--%>
                <%--    return;--%>
                <%--}--%>
                window.location.href = "${basePath}/score/list";
            },
            error: function (e) {
                console.log("e:" + e);
            }
        });
    }

</script>
<style type="text/css">
    .container2 {
        display: flex;
        /*justify-content: space-around;*/
    }
</style>
